#泫雨飘零

echo -e "\033[32m
_____________________________________________________________
 
        Ren guokai:https://gitee.com/xypl
        Zsh与Oh-my-zsh 插件安装集成脚本，已支持Centos/Ubuntu/OpenEuler
_____________________________________________________________
 \033[0m"
 
#查看当前SHELL
echo -e "\033[32m 查看当前shell \033[0m"
echo $SHELL

# 用户家目录
USER_HOME=$HOME
if [ ! -d "${USER_HOME}" ]; then
    echo -e "\033[31m 当前用户家目录不存在 \033[0m"
    echo -e "\033[31m 本脚本不支持当前用户 \033[0m"
    exit 1
else
    echo -e "\033[32m 当前用户家目录存在 \033[0m"
    echo -e "\033[32m 前置条件 => 通过 \033[0m"
fi

# 必要条件判断：Git
EnableGit=0
if ! type git >/dev/null 2>&1; then
    echo -e "\033[31m 必要条件:git => 未安装 \033[0m"
    echo -e "\033[31m 请先安装git \033[0m"
    exit 1
else
    echo -e "\033[32m 必要条件:git => 已安装 \033[0m"
    EnableGit=1
fi

echo -e "\033[32m_____________________________________________________________\033[0m"
echo -e "\033[33m 是否确认安装本脚本？\033[0m"
echo -e "\033[33m 输入y后回车=>继续安装；其他键后回车=>取消安装 \033[0m"
read temp
if [ ${temp} = "y" ];then
    echo -e "\033[32m 继续安装zsh和oh-my-zsh \033[0m"
else
    echo -e "\033[32m 脚本已经终止 \033[0m"
    exit 1
fi



# Redhat系下安装zsh
echo -e "\033[32m 安装并替换为zsh（需有sudo权限） \033[0m"
sudo yum install zsh -y

# Debian系下安装zsh
sudo apt install zsh -y

echo -e "\033[32m ======================== \033[0m"


echo -e "\033[31m 正在将shell配置为zsh......如提示命令未发现或重复可忽略 \033[0m"
echo -e "\033[31m  \033[0m"
# Centos/Ubuntu切换shell命令
chsh -s /bin/zsh >/dev/null
# openeuler切换shell命令
sudo usermod -s /bin/zsh ${USER} >/dev/null
touch ~/.zshrc


cd ${USER_HOME}
ohmyzshOld=".oh-my-zsh"
if [ -d "$ohmyzshOld" ]; then
    echo -e "\033[32m -发现已经安装oh-my-zsh \033[0m"
    echo -e "\033[32m -备份.oh-my-zsh为oh-my-zsh-Bak \033[0m"
    echo -e "\033[32m -如需查看之前oh-my-zsh可复盘 \033[0m"
    mv -f ${USER_HOME}/${ohmyzshOld} ${USER_HOME}/oh-my-zsh-Bak >/dev/null 2>&1
fi

cd ${USER_HOME}
echo -e "\033[32m 从xypl下载ohmyzsh \033[0m"
git clone https://gitee.com/xypl/ohmyzsh.git ~/.oh-my-zsh


echo -e "\033[32m 更换模板配置文件 \033[0m"
cp ${USER_HOME}/.oh-my-zsh/.zshrc ${USER_HOME}/.zshrc >/dev/null 2>&1


cd ${USER_HOME}
echo -e "\033[32m 开始配置插件：zsh-syntax-highlighting、zsh-autosuggestions \033[0m"
git clone https://gitee.com/xypl/zsh-syntax-highlighting.git ${USER_HOME}/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting >/dev/null 2>&1
git clone https://gitee.com/xypl/zsh-autosuggestions.git ${USER_HOME}/.oh-my-zsh/custom/plugins/zsh-autosuggestions >/dev/null 2>&1

echo -e "\033[32m 加载配置中 \033[0m"
source ~/.zshrc >>/dev/null 2>&1
echo -e "\033[32m ======================== \033[0m"

echo -e "\033[32m 配置完成，请重启Terminal查看 \033[0m"
echo -e "\033[32m 愉快使用zsh和oh-my-zsh吧( ´▽｀) \033[0m"